﻿using KingerRobot.MexicoSailunMDC.Dao;

namespace KingerRobot.MexicoSailunWMS.SpiService;
internal interface IRcsLocation
{

    /// <summary>
    /// 修改货位和货位跟踪(skuId)
    /// </summary>
    /// <param name="skuId">单元ID</param>
    /// <param name="startLocId">开始 清除</param>
    /// <param name="targetLocId">目标 添加</param>
    /// <returns></returns>
    int UpdateLocationAndWcsLocWithSkuId(
       long? skuId,
       long? startLocId = 0,
       long? targetLocId = 0,
       bool isDelTarget = false);
    /// <summary>
    /// 查询所有库位
    /// </summary>
    /// <returns></returns>
    List<PORcsLocation> GetLocations();
    /// <summary>
    /// 通过位置ID获取位置信息
    /// </summary>
    /// <param name="id">位置Id</param>
    /// <returns>位置信息</returns>
    PORcsLocation GetLocationById(long id);
    /// <summary>
    /// 通过位置ID获取库位类型
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    int GetLocationTypeById(long id);
    /// <summary>
    /// 通过 Code 获取位置
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    PORcsLocation GetLocationByCode(string code);
    /// <summary>
    /// 通过 Type 获取位置
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    List<PORcsLocation> GetLocationByType(int type);
    /// <summary>
    /// 通过位置ID获取位置是否存在
    /// </summary>
    /// <param name="id">位置Id</param>
    /// <returns>true:存在；false:不存在</returns>
    bool HasLocationById(long id);


    /// <summary>
    /// 清除库位绑定信息
    /// </summary>
    /// <param name="locId">库位ID</param>
    /// <returns></returns>
    int ClearLocationHasTask(long locId);
    /// <summary>
    /// 清除已绑定的 taskId
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int ClearLocationHasTaskByTaskId(long taskId);


    /// <summary>
    /// 查找所有可用库存
    /// </summary>
    /// <returns></returns>
    List<PORcsLocation> GetAllLocations();


    /// <summary>
    /// 查找所有禁用库存
    /// </summary>
    /// <returns></returns>
    List<PORcsLocation> GetAllDisableLocations();
    /// <summary>
    /// 条码绑定
    /// </summary>
    /// <param name="id"></param>
    /// <param name="productCode"></param>
    /// <returns></returns>
    int UpdateLocProductCode(long id, string productCode);
    /// <summary>
    /// 查找所有可用入库货位（无任务）
    /// </summary>
    /// <returns></returns>
    List<PORcsLocation> GetAllInNoTaskLocations();
    /// <summary>
    /// 查找所有可出库货位（无任务）
    /// </summary>
    /// <returns></returns>
    List<PORcsLocation> GetAllOutNoTaskLocations();
    /// <summary>
    /// 查找无放货货位
    /// </summary>
    /// <returns></returns>
    List<PORcsLocation> GetNoGoodsLocations();

    /// <summary>
    /// 查找所有【入库放货位、出库有货位】
    /// </summary>
    /// <returns></returns>
    LocationHasBean GetHasSkuLocations();


    /// <summary>
    /// 获取堆垛机负责的单一空货位
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    List<LocationInfo> GetSingleLocation(List<LocationInfo> pORcsLocations);
    /// <summary>
    /// 获取堆垛机负责的成对空货位
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    List<LocationInfo> GetDoubleLocation(List<LocationInfo> pORcsLocations);


    /// <summary>
    /// 通过 Ids 获取位置
    /// </summary>
    /// <param name="locId"></param>
    /// <returns></returns>
    List<PORcsLocation> GetLocationsByLocIds(List<long?> ids);

    /// <summary>
    /// 修改库位有货
    /// </summary>
    /// <param name="materialId"></param>
    /// <param name="locId"></param>
    /// <returns></returns>
    int UpdateLocationHasGood(long? materialId, long? locId, DateTime? mdTime);
    /// <summary>
    /// 手工入库绑定
    /// </summary>
    /// <param name="materialId"></param>
    /// <param name="locId"></param>
    /// <param name="productCode"></param>
    /// <returns></returns>
    int UpdateInLocationHasGood(long? materialId, long? locId, string productCode);
    /// <summary>
    /// 修改库位无货
    /// </summary>
    /// <param name="locId"></param>
    /// <returns></returns>
    int UpdateLocationNoGood(long? locId);

    /// <summary>
    /// 修改库位可用性
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    int UpdateLocEnable(long id);

    /// <summary>
    /// 修改库位可用性，包括禁用信息
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    int ChangeLocEnable(LocEnableParam param);
    /// <summary>
    /// 修改入库可用性
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    int UpdateInEnable(long id);
    /// <summary>
    /// 修改出库可用性
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    int UpdateOutEnable(long id);
    /// <summary>
    /// 禁用货位
    /// </summary>
    /// <param name="id"></param>
    /// <param name="taskNo">任务流水号</param>
    /// <returns></returns>
    int UpdateLocUnEnable(long id, int taskNo = 0);

    int UpdateLocCoord(CoordPara coordPara);
    List<CrnEnableLocationBean> GetCrnEnableLocation();
    long GetWarehouseByLocationID(long locId);

    List<LocationBeanV2> GetLocationV2();

    List<StockPairBean> GetStockPair();
}

internal class LocationHasBean
{
    /// <summary>
    /// 无货
    /// </summary>
    public List<PORcsLocation> NoGoods { get; set; }
    /// <summary>
    /// 有货
    /// </summary>
    public List<PORcsLocation> InStock { get; set; }
}

internal class LocationInfo
{
    public long? Id { get; set; }
    public long? MaterialId { get; set; }
    public long? GroupId { get; set; }
    public int? GroupIndex { get; set; }
    public DateTime? MdTime { get; set; }
    public long? CrnId { get; set; }

    // 出库订单
    public POWmsOutOrderSummary Summary { get; set; }
    /// <summary>
    /// 是否双库位有货
    /// </summary>
    public bool IsDouble { get; set; }
    public long? AreaId { get; set; }
}
internal class LocationGroupInfo
{
    public long? CrnId { get; set; }
    public long? MaterialId { get; set; }
    public DateTime? MinTime { get; set; }
    //public int Count { get; set; }
    public List<LocationInfo> LocationInfos { get; set; }
}